package app

import (
	"gitee.com/krio/grpc-common/cmd/interceptor"
	"gitee.com/krio/grpc-common/cmd/lib"
	"gitee.com/krio/grpc-common/handler"
	pbCommon "gitee.com/krio/grpc-pb/pb/common"
	"gitee.com/krio/helper/logger"

	grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
	"google.golang.org/grpc"
)

func newGRPC() *grpc.Server {
	s := grpc.NewServer(
		grpc.UnaryInterceptor(
			// 单向调用的拦截器链
			grpc_middleware.ChainUnaryServer(
				interceptor.GrpcLogger,
				interceptor.GrpcRecover,
			),
		),
	)
	pbCommon.RegisterRegionServer(s, &handler.RegionHandler{})
	return s
}

func Run() {
	s := newGRPC()
	err := lib.GRPCServer(s)
	if err != nil {
		logger.Fatal(err)
	}
}
